package com.sanno.maintain.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sanno.common.entity.SccRole;
import com.sanno.common.result.Result;
import com.sanno.common.result.ResultCodeEnum;
import com.sanno.maintain.service.Maintain3Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/maintain/SccRole")
@Api(tags = "系统维护-分配角色权限")
@CrossOrigin
public class Maintain3Controller {

    @Resource
    private Maintain3Service maintain3Service;

    @RequestMapping(value = "findSccRole",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有",notes = "",httpMethod = "GET")
    public Result querySccRole(){
        QueryWrapper<SccRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("status",1);
        List<SccRole> menuList = maintain3Service.list(queryWrapper);
        return Result.ok(menuList);
    }

    @RequestMapping(value = "{id}",method = RequestMethod.POST)
    @ApiOperation(value = "id删除",notes = "",httpMethod = "POST")
    public Result delSccRole(@PathVariable("id")int id){
        SccRole sccRole = new SccRole();
        sccRole.setStatus(0);
        UpdateWrapper<SccRole> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("role_id",id);
        boolean isOk = maintain3Service.update(sccRole,updateWrapper);
        return Result.build(isOk, ResultCodeEnum.SUCCESS);
    }

    @RequestMapping(value = "addSccRole",method = RequestMethod.POST)
    @ApiOperation(value = "添加",notes = "",httpMethod = "POST")
    public Result addSccRole(SccRole sccRole){
        boolean idOk = maintain3Service.save(sccRole);
        return Result.build(idOk,ResultCodeEnum.SUCCESS);
    }

    @RequestMapping(value = "updateSccRole",method = RequestMethod.POST)
    @ApiOperation(value = "修改",notes = "",httpMethod = "POST")
    public Result updateSccMenu(SccRole sccRole){
        boolean isOk = maintain3Service.updateById(sccRole);
        return Result.build(isOk,ResultCodeEnum.SUCCESS);
    }

}
